#论坛登录页面
import time
import os
from selenium.webdriver.common.by import By
from common.Utils import ForumDriver
class ForumLogin:
    url=""
    def __init__(self):
        self.url="http://127.0.0.1:58080/sign-in.html"

        self.driver=ForumDriver.driver
        self.driver.get(self.url)

    def FoeumSucLogin(self):
#成功登录
     print("正确的用户名，正确的密码")
     self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("333")
     self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("333")
     self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
#是否跳转到论坛主页
     self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post")
     ForumDriver.getScreenshot()

     self.driver.back()

    def FoeumFaiLogin(self):
   #异常登录
     print("输入错误的用户名，输入错误的密码")
     self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
     self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
     self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("31")
     self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("31")
     self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
    #出现用户名或者密码错误的警告弹窗
     ForumDriver.getScreenshot()
     time.sleep(2)

     print("输入错误的用户名，输入正确的密码")
     self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
     self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
     self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("31")
     self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("333")
     self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
     # 出现用户名或者密码错误的警告弹窗
     ForumDriver.getScreenshot()
     time.sleep(2)

     print("输入正确的用户名，输入错误的密码")
     self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
     self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
     self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("333")
     self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("33")
     self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
    # 出现用户名或者密码错误的警告弹窗
     ForumDriver.getScreenshot()
     time.sleep(2)

     print("输入正确的用户名，输入空的密码")
     self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
     self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("333")
     self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
     text=self.driver.find_element(By.CSS_SELECTOR,"#signInForm > div.mb-2 > div > div").text
     print(text)
     assert text =="密码不能为空"


     print("输入空的用户名，输入正确的密码")
     self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
     self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("333")
     self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
     text1 = self.driver.find_element(By.CSS_SELECTOR, "#signInForm > div.mb-3 > div").text
     print(text1)
     assert text1 == "用户名不能为空"


     print("输入空的用户名，输入空的密码")
     self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
     self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
     self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
     text2 = self.driver.find_element(By.CSS_SELECTOR, "#signInForm > div.mb-3 > div").text
     print(text2)
     assert text2 == "用户名不能为空"
     text3 = self.driver.find_element(By.CSS_SELECTOR, "#signInForm > div.mb-2 > div > div").text
     print(text3)
     assert text3 == "密码不能为空"
     time.sleep(2)

    def ForumJopLogin(self):
         self.driver.find_element(By.CSS_SELECTOR,"body > div > div > div > div:nth-child(1) > div > div.text-center.text-muted.mt-3 > a").click()
         ForumDriver.getScreenshot()
         time.sleep(1)
         self.driver.find_element(By.CSS_SELECTOR,"#submit")
         self.driver.back()
         time.sleep(1)
        #明文显示符号
         self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("333")
         self.driver.find_element(By.CSS_SELECTOR,"#password_a > svg").click()
         ForumDriver.getScreenshot()

# sign=ForumLogin()
# sign.FoeumSucLogin()
# sign.FoeumFaiLogin()
# #sign.ForumJopLogin()